(function (window) {
    var Dialog = function (el) {
        if (typeof el == 'undefined') {
            el = document.body;
        }
        this.el = el;
        this.$el = $(el);
        this.$dialog = null;
        this.replace = true;
        this.init();
    }

    Dialog.prototype = {
        init: function () {
            var innerHTML = this.$el.html();
            this.$el.html('');
            if (innerHTML && innerHTML.length > 0) {
                this.replace = false;
            }
            this.$dialog = $([
'<div class="dialog">',
'    <div class="dialog-inner">',
'        <div class="dialog-body bottomH">',
innerHTML,
'        </div>',
'        <div class="dialog-split"></div>',
'        <div class="dialog-footer">',
'            <a class="btn btn-link" href="javascript:;" id="dialog-ok">确认</a>',
'        </div>',
'    </div>',
'</div>'
            ].join(''));
            var self = this;
            this.$dialog.find('#dialog-ok').click(function () {
                self.hide();
            });
            this.hide();
            this.$el.append(this.$dialog);
        },
        show: function (txt) {
            if (this.replace)
                this.$dialog.find('.dialog-body').html(txt);
            this.$dialog.show();
        },
        hide: function () {
            this.$dialog.hide();
        }
    };

    window.Dialog = Dialog;
})(window);